Emit specialized OpenAI tool results only once - #6921
Conversation
🦋 Changeset detectedLatest commit: 8522a9f The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Important
The implementation fix is not yet on this branch. The reproduction test captures the bug correctly but the source change to fix it is absent. Per the PR description, the fix needs to be added to this branch before merging.
Reviewed changes
- Reproduction test for duplicate specialized tool output: A new test captures the outgoing HTTP request body and verifies that
apply_patchresults emit only the specializedapply_patch_call_outputitem, not also a genericfunction_call_output.
⚠️ Missing implementation fix
The reproduction test in packages/ai/openai/test/OpenAiDuplicateSpecializedToolOutputAudit.test.ts is correct and will fail against the current source. However, the fix to packages/ai/openai/src/OpenAiLanguageModel.ts lines 1126–1160 is not present on this branch. Each specialized block (1126–1133 for apply_patch, 1135–1143 for shell, 1145–1153 for local_shell) needs a continue to prevent fall-through to the unconditional function_call_output push at line 1155.
Technical details
# Missing `continue` after specialized output blocks
## Affected sites
- `packages/ai/openai/src/OpenAiLanguageModel.ts:1126-1160` — three independent `if` blocks for specialized tool outputs are followed by an unconditional `function_call_output` push
## Required outcome
- Each specialized block must `continue` to the next iteration after pushing its specialized message, skipping the generic `function_call_output` on line 1155⚠️ Missing tests for shell and local_shell
The same bug affects shell and local_shell results identically, but the test file only covers apply_patch. Add parallel test cases for these two tool types to ensure complete regression coverage.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added
continueafter each specialized tool output block — prevents fall-through to the unconditionalfunction_call_outputpush forapply_patch_call_output,shell_call_output, andlocal_shell_call_output. - Fixed shell tool name lookup — changed
"OpenAiFunctionShell"to"OpenAiShell"on line 785, which was a latent bug where theshellToolvariable was never populated. - Added three mocked-HTTP regression tests — each test verifies that a specialized tool result produces exactly the expected output type and no duplicate generic
function_call_output. Coversapply_patch,shell, andlocal_shell.
All prior review feedback (missing implementation fix, missing tests for shell and local_shell) is addressed. All three new tests pass.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
apply_patch, shell, and local_shell results are sent once in their specialized output form and again as incompatible generic function_call_output items.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
Specialized OpenAI tool results are emitted twice
Module:
ai/openai/OpenAiLanguageModelAudit ID:
adapters-ai-9-openai-duplicate-specialized-tool-outputSeverity / confidence: high / high
What happens
apply_patch, shell, and local_shell results are sent once in their specialized output form and again as incompatible generic function_call_output items.
Why it happens
After pushing a specialized output, control falls through to the unconditional generic function_call_output path.
Expected behavior
Specialized Responses API call types have distinct corresponding output item types.
Relevant implementation
These links and excerpts are pinned to audit base
c9b56ab507f224426ee8388dc450da447ec4715f.packages/ai/openai/src/OpenAiLanguageModel.ts:1126-1160View problematic code at
packages/ai/openai/src/OpenAiLanguageModel.ts:1126-1160View exact lines on GitHub
Reproduction
pnpm test --run packages/ai/openai/test/OpenAiDuplicateSpecializedToolOutputAudit.test.tsObserved failure: The specialized result produced both apply_patch_call_output and function_call_output.
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
pnpm test --run packages/ai/openai/test/OpenAiDuplicateSpecializedToolOutputAudit.test.tsAudit provenance
c9b56ab507f224426ee8388dc450da447ec4715f8f9499f562729f5f7b08d8bcc4db86b4aeff8a21adapters-ai-9-openai-duplicate-specialized-tool-outputCloses EFF-338